home *** CD-ROM | disk | FTP | other *** search
- /*=========================================================================
- Module: SortSelection
-
- Purpose: Get a selection and sort it. Then update the selection with
- the sorted selection.
-
- returns: UpdateSel to the scrap.
-
- Functional Details:
-
- Get a valid selection
- if error
- exit
- Build the selection into lines of text
- if error
- exit
- Sort the selection lines
- Update the selection with the sorted lines
- if error
- exit
- Dispose all allocated storage
-
- =========================================================================*/
- #include "ToolSort.h"
- #include <SetUpA4.h>
-
- void
- main()
- {
- SelLine selLine; /* Array of handles to selection lines */
- SelRec validSel; /* Handle to selection and selection length */
- Text txt; /* Handle to selection in text format */
- long err;
- long size;
- int i;
-
- RememberA0(); /* Access globals in code resource */
- SetUpA4(); /* Globals accessed off of A4 */
-
- err = GetValidSel( &validSel);
- if ( err != No_Error )
- DisplayError( err );
-
- if ( validSel.sel != NIL )
- {
- size = CompactMem((Size) (2*validSel.length) +1024);
- if ( size < 2*validSel.length+1024 )
- { /* Error not enough memory */
- err = Memory_Error;
- DisposHandle( validSel.sel );
- DisplayError( err );
- }
- else
- {
- err = BuildLines(validSel, &selLine);
- DisposHandle( validSel.sel ); /* free memory */
- if ( err )
- DisplayError( err );
-
- if (selLine.noLines > 0) /* test 1 line */
- {
-
- Bubble(selLine.lines, sizeof(selLine.lines[0]),
- selLine.noLines, Comp, Swap);
-
- err = SelToText( selLine, &txt );
-
- for ( i=0; i<selLine.noLines; i++ ) /* Dispose selLine */
- {
- if ( selLine.lines[i] != NIL )
- {
- DisposHandle( selLine.lines[i] );
- selLine.lines[i] = 0L; /* mark it disposed */
- }
- }
- if ( selLine.lines != NIL )
- {
- DisposPtr( selLine.lines );
- selLine.lines = 0L; /* mark it disposed */
- }
-
- if ( txt != NIL )
- {
- err = UpdateSel( txt );
- DisposHandle( txt );
- if ( err != noErr )
- DisplayError( err );
- }
- }
- }
- }
-
- RestoreA4(); /* restore reg A4 to its original value */
- }